package com.senlingspace.web.controller.pos;

import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.core.domain.model.LoginUser;
import com.senlingspace.common.core.page.TableDataInfo;
import com.senlingspace.system.domain.dto.ShopResponse;
import com.senlingspace.system.domain.vo.ProductQueryRequest;
import com.senlingspace.system.domain.vo.ProductResponse;
import com.senlingspace.system.service.ISlkjShopProductService;
import com.senlingspace.system.service.ISlkjShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 门店Controller
 *
 * @author SenlingSpace
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/pos/shop")
public class ShopController extends BaseController {
    @Autowired
    private ISlkjShopService slkjShopService;

    @Autowired
    private ISlkjShopProductService iSlkjShopProductService;


    /**
     * 获取门店详细信息
     */
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId) {
        return success(slkjShopService.selectSlkjShopByShopId(shopId));
    }

    /**
     * 查询登录账号下的门店列表
     */
//    @PreAuthorize("@ss.hasPermi('system:shop:listshop')")
    @GetMapping("/listShop")
    public TableDataInfo getShopsByDeptId() {
        LoginUser loginUser = getLoginUser();
        Long deptId = loginUser.getDeptId();
        List<ShopResponse> shops = slkjShopService.getShopsByDeptId(deptId);
        return getDataTable(shops);
    }

    /**
     * 查询门店的商品类别列表
     */
    @GetMapping("/tpyeIds")
    public TableDataInfo getProductTypesByShopId(Long shopId) {
        List<ProductResponse> list = iSlkjShopProductService.getProductTypesByShopId(shopId);
        return getDataTable(list);
    }

    /**
     * 查询门店的商品列表
     */
    @GetMapping("/products")
    public TableDataInfo getProductsByShopAndName(ProductQueryRequest productQueryRequest) {

        List<ProductResponse> list = iSlkjShopProductService.getProductsByShopAndName(
                productQueryRequest.getShopId(), productQueryRequest.getProductName(), productQueryRequest.getProductTpyeId(),null);

        return getDataTable(list);
    }

}
